Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: fix bytearray might be passed into lru_cached function #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JamzumSum
Copy link

Most type checkers will fit bytearray into bytes automatically. However, the former is hashable but the later is not hashable. Our decode_address is a lru_cache function and requires hashable inputs. This will trigger an exception says "unhashable type: 'bytearray'".

Example:

from socksio.socks5 import SOCKS5Reply

data = bytearray(b'\x05\x00\x00\x01\x7f\x00\x00\x01\x1e\xd2')
SOCKS5Reply.loads(bytes(data))  # OK
SOCKS5Reply.loads(data)         # ValueError

Copy link
Owner

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, could we add a test case to ensure we don't regress on this behavior?

@JamzumSum
Copy link
Author

Thanks for this, could we add a test case to ensure we don't regress on this behavior?

Sorry for my late reply. I've add a few code to test bytearray input in 9f992b3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants